package com.x.account;

public class AccountDemo {
    public static void main(String[] args) {

        boolean isOut = true;
        int balance = 30000;//初始金额
        String info = "";

        while(isOut){
            System.out.println("--------------记账软件开始界面---------------");
            System.out.println("1 收支明细");
            System.out.println("2 登记收入");
            System.out.println("3 登记支出");
            System.out.println("4 退  出\n");
            System.out.println("请选择(1——4):");

            //接受一个字符，用户选择“1”、“2”、“3”、“4”
            char selection = Utility.readMenuSelection();

            switch (selection) {
                case '1' -> {
                    System.out.println("----------------当前收支明细----------------");
                    System.out.println("收支      账户金额       收支金额       备注");
                    System.out.println(info);
                    System.out.println("------------------------------------------");
                }
                case '2' -> {
                    System.out.println("本次收入金额:");
                    int money1 = Utility.readNumber();
                    if (money1 > 0)
                        balance += money1;
                    System.out.println("本次收入说明:");
                    String note1 = Utility.readString();
                    info += "收入" + "       " + balance + "         " + money1 + "         " + note1 + "\n";
                    System.out.println("----------------登记完成----------------");
                }
                case '3' -> {
                    System.out.println("本次支出金额:");
                    int money2 = Utility.readNumber();
                    if (money2 > 0 && balance >= money2)
                        balance -= money2;
                    System.out.println("本次支出说明:");
                    String note2 = Utility.readString();
                    info += "支出" + "       " + balance + "         " + money2 + "         " + note2 + "\n";
                    System.out.println("----------------登记完成----------------");
                }
                case '4' -> {
                    System.out.println("确认是否退出？Y/N");
                    char isExit = Utility.readConfirmSelection();
                    if (isExit == 'Y') {
                        isOut = false;
                    }
                }
            }
        }
    }
}
